/**
 * Created by hongwen on 2017/7/10.
 */
import message from '../../../../api/config/channel/message-config'
import * as globalTypes from '../../../../mutation-types'
// ==================短信  闪信  设置==========================
/**
 * 获取挂机短信
 * @param {Object} data
 */
export const queryHangupMessageTemplate = ({commit, state, rootState, dispatch}, data) => {
  return message.queryHangupMessageTemplate(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 保存挂机短信配置
 * @param {Object} data
 */
export const saveCallMessageTemplate = ({commit, state, rootState, dispatch}, data) => {
  return message.saveCallMessageTemplate(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 闪信模板: 查询列表
 * data:{"account":"N00000000531", page:1 ,limit:0 }
 * **/
export const queryFlashSmsExamine = ({commit, state, rootState, dispatch}, data) => {
  return message.queryFlashSmsExamine(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 获取可用通道
 * data:{"type":"flashSmsChannel"}
 * **/
export const getClientDicCache = ({commit, state, rootState, dispatch}, data) => {
  return message.getClientDicCache(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 新建闪信模版
 * @param data.account String 账户
 * @param data.name String 模版名称
 * @param data.content String 模版内容
 * @param data.channel String 通道id
 * @returns {*}
 */
export const addShanxinTemplete = ({commit, state, rootState, dispatch}, data) => {
  return message.addShanxinTemplete(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/***
 * 根据_id获取闪信模板详情(修改前的回显)
 * data:{"_id":"N000000005310017"} 模板id
 * **/
export const getShanxinTempleteById = ({commit, state, rootState, dispatch}, data) => {
  return message.getShanxinTempleteById(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/***
 * 更新单个闪信模块(修改后的保存)
 data: {
        "account":"账户id",
        "_id":"模板id",
        "num":"17",
        "name":"模版名称"
        "content":"模版内容",
        "channel":"通道"
    }
 * **/
export const updateShaninTemplete = ({commit, state, rootState, dispatch}, data) => {
  return message.updateShaninTemplete(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/***
 * 删除单个闪信模块
 * data:{"_id":"N000000005310017"}
 * **/
export const deleteShanxinTemplete = ({commit, state, rootState, dispatch}, data) => {
  return message.deleteShanxinTemplete(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/***
 * 停用或启用闪信模板
 data:{
        "_id":"N000000005310009",
        "status":"stop" // "open" 是启动 "stop" 是停用
     }
 **/
export const changeShanxinTemplete = ({commit, state, rootState, dispatch}, data) => {
  return message.changeShanxinTemplete(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/***
 * 闪信模板  签名
 data::{"account":"N00000001366"}
 **/
export const queryShanxinSign = ({commit, state, rootState, dispatch}, data) => {
  return message.queryShanxinSign(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
